export class Queue<T> {

    private items: T[] = [];

    constructor(...args) {
        this.items = new Array(...args);
        Object.defineProperty(this, "items", { enumerable: false });
    }

    Enqueue(item: T) {
        this.items.push(item);
    }

    Dequeue(): T | undefined {
        return this.items.shift();
    }

    Peek(): T | undefined {
        return this.items[0];
    }

    get Count(): number {
        return this.items.length;
    }

    TryDequeue() {
        if (this.Count != 0) {
            let item = this.Dequeue();
            return item;
        }
        return null;
    }

    Clear() {
        this.items.length = 0;
    }

    ToArray(): T[] {
        return this.items.slice();
    }

}